package com.lakeworks.framework.config;


import com.lakeworks.listener.distribution.DistributionListener;
import com.lakeworks.listener.distribution.DistributionType;
import com.lakeworks.service.impl.OprProductServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.reflect.InvocationTargetException;

@Configuration
public class DistributionConfig {

    private static final Logger log = LoggerFactory.getLogger(DistributionConfig.class);


    @Value("${lakeworks.distribution}")
    private String code;

    @Bean
    public DistributionListener getListener() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        DistributionListener listener = DistributionType.valueOf(code).getImplementation().getDeclaredConstructor().newInstance();
        log.info("二次分配线机构代码::[{}]----响应监听实例::[{}]",code,listener);
        return listener;
    }


}
